#include "generator.h"
#include "ui_generator.h"
#include <QProcess>
#include <QFileDialog>

Generator::Generator(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Generator)
{
    ui->setupUi(this);

    loadFile("D:/Max/Programowanie/Grafika1/Projekt/Raw/tmp/diagram.jpg");

}

Generator::~Generator()
{
    delete ui;
}

void Generator::on_rb_w_clicked()
{
    dc.setBalans(QString("-w"));

}

void Generator::on_rb_a_clicked()
{
     dc.setBalans(QString("-a"));
}


void Generator::on_cb_M_clicked(bool checked)
{
    dc.setMacierzBarw(checked?"+M":"-M");
}

void Generator::on_sb_H_valueChanged(const QString &arg1)
{
    dc.setSwiatlo(arg1);
}

void Generator::loadFile(QString sciezka)
{
    qDebug() << "Lecimy +++ " << sciezka;
    dc.setFileName(sciezka);
    on_pb_podglad_clicked();
}

void Generator::changeR()
{
    qDebug("dasdsadasdas");
    on_rb_r_clicked();
}

void Generator::on_pb_podglad_clicked()
{
    ui->pb_podglad->setEnabled(false);
    dc.save();

    QString tiffName = dc.getFileName();
    int ind = tiffName.lastIndexOf(".");
    tiffName.remove(ind,tiffName.length()-ind);
    qDebug() << "Probuje zaladowadac tiff-a :" << tiffName;
    tiffName += tr(".tiff");
    ui->zoomer->loadNewImage(tiffName);
    ui->pb_podglad->setEnabled(true);
}

void Generator::on_sb_q_valueChanged(const QString &arg1)
{
    dc.setMozaikowanie(arg1);
}

void Generator::on_pb_zapisz_clicked()
{
    QString name = QFileDialog::getSaveFileName(this, tr("Zapisz Plik"),
                                "",
                                tr("Images (*.tiff)"));

    if( !name.isNull() )
    {
      qDebug( name.toAscii() );
    }
    ui->zoomer->getImage().save(name,"TIFF");
}

void Generator::on_rb_r_clicked()
{
    QString pom;
    QString val = QString("-r ")+pom.number(ui->sbr_r->value())
            +" "+pom.number(ui->sbr_g1->value())
            +" "+pom.number(ui->sbr_b->value())
            +" "+pom.number(ui->sbr_g2->value());
    dc.setBalans(val);
}



void Generator::on_sb_b_valueChanged(const QString &arg1)
{
    dc.setJasnosc(arg1);
}

void Generator::on_sb_k_valueChanged(const QString &arg1)
{
    dc.setCzern(arg1);
}

void Generator::on_cb_4_clicked(bool checked)
{
    dc.setZapis16bit(checked?"-4":"");
}

void Generator::on_cb_w_clicked(bool checked)
{
    dc.setRozjasnianie(checked?"-W":"");
}
